/**
 * 课程详情页JS调用
 */

var course_package_page = 1;

function remainTime() {
	var iMinute, iSecond;
	var sMinute="", sSecond="", sTime="";
	if (iTime >= 0) {
		iMinute = parseInt((iTime/60)%60);
		if (iMinute > 0){
			sMinute = '&nbsp;<em>' + iMinute + '</em>：';
		} else if(iMinute <= 0){
			sMinute = '&nbsp;<em>00</em>：';
		} 
		iSecond = parseInt(iTime%60);
		if (iSecond >= 0){
			sSecond = '&nbsp;<em>' + iSecond + '</em>';
		}
		sTime='<span>距上课</span>&nbsp;<em> 00 </em>：'+sMinute+sSecond;
		if(iTime==0){
			clearTimeout(Account);
			sTime='<span class="cor">第'+StepIndex+'章第'+ClassIndex+'节正在直播中...</span>';
		} else {
			Account = setTimeout("remainTime()",1000);
		}
		iTime=iTime-1;
	} else {
		sTime='<span class="cor">第'+StepIndex+'章第'+ClassIndex+'节正在直播中...</span>';
	}
	$("#remain_time").html(sTime);
}

function getBoxContent(tab) {
/*	$.ajax({
		url:"/?mod=course&act=show&do="+tab+"&sid="+Course.SID+"&courseid="+Course.CourseID+"&r="+Math.random(),
		type:"get",
		beforeSend:function(){
			$("#box_content").html('<div class="tc pt30"><img border="0" src="http://res.ckimg.com/sites/www/v2/images/public/loading.gif" /></div>');
		},
		success:function(data) {
			$("#box_content").html(data);
		}
	});*/
}

function getCommentVote() {
	$.ajax({
		url:"/?mod=course&act=show&do=comment&sid="+Course.SID+"&courseid="+Course.CourseID+"&comment_flag=1&r="+Math.random(),
		type:"get",
		beforeSend:function(){
			$("#box_content").html('<div class="tc pt30"><img border="0" src="http://res.ckimg.com/sites/www/v2/images/public/loading.gif" /></div>');
		},
		success:function(data) {
			$("#box_content").html(data);
		}
	});
}

//跳转订单倒计时
function timerRedirect () {
	cTime--;
	if (cTime <= 0) {
		if (typeof($('#alertTimeClose').attr('u')) != 'undefined') {
			window.location.href = $('#alertTimeClose').attr('u');
		}
		return false;
	} else {
		$('#alertTimeClose').text(cTime);
		window.setTimeout('timerRedirect()', 1000);
	}
}

function addtoCart(){
	cTime = 3;
	if(KK.checkLogin() === false){
		//$.ckLoginBoxy();
		var url = 'http://www.chuanke.com/'+Course.SID+'-'+Course.CourseID+'.html#cart';
		url = KK.base64_encode(url);
		url = url.replace(/\//, '_');
		location.href = "http://passport.chuanke.com/login/index/ret/"+url;
		return false;
	}		
	$.ajax({
		url:'/?mod=cart&act=operate&do=add&sid='+Course.SID+'&courseid='+Course.CourseID+'&token='+ptoken+'&r='+Math.random(),
		type:'get',
		dataType:'json',
		beforeSend:function(){
			loading = $.ckTipsBoxy({type:"loading", mask:true, message:"提交数据中..."});
		},
		success:function(ret) {
			loading.cancel();
			if (ret.code == 3) {
				setInterval("timerRedirect();", 1000);
				$.ckAlert({message:ret.data,width : 500, height : 200});
			} else if (ret.code == 4) {
				window.location.href = ret.data;
			} else if(ret.code == 0){
				var msg = '<div class="d_d_gx lh25 mt25 mb30 f14 c_777">';
				msg += '<img class="img" src="http://res.ckimg.com/sites/www/v2/images/public/ico_ok_25x25.png">';
				msg += '<p>已加入购物车！</p>';
				msg += '<p class="f12"><a href="/?mod=cart&act=show" target="_blank">查看我的购物车>></a></p>';
				msg += '</div>';
				msg += '<p class="tc">';
				msg += '<a href="javascript:;" id="try_success_confirm" class="c_btn37a"><span>确 定</span></a>';
				msg += '</p>';
				var ajaxBox = $.ckBoxy({
					content: msg,
					title : "提示",
					width : 338,
					height : 236,
					callback : function(){
						$(".close").click(function(){
							ajaxBox.cancel();
						});
						$("#try_success_confirm").live('click', function(){
							ajaxBox.cancel();
						});
					}
				});
				KK.updateCartCount();
			}
		}
	});	
}

//课程套餐添加到购物车
function packtoCart(packid) {
	if(KK.checkLogin() === false){
		var url = 'http://www.chuanke.com/'+Course.SID+'-'+Course.CourseID+'.html#pcart';
		url = KK.base64_encode(url);
		url = url.replace(/\//, '_');
		location.href = "http://passport.chuanke.com/login/index/ret/"+url;
		return false;
	}
	$.ajax({
		url:'/?mod=cart&act=operate&do=packadd&packid='+packid+'&sid='+Course.SID+'&courseid='+Course.CourseID+'&token='+ptoken+'&r='+Math.random(),
		type:'get',
		dataType:'json',
		beforeSend:function(){
			loading = $.ckTipsBoxy({type:"loading", mask:true, message:"提交数据中..."});
		},
		success:function(ret) {
			loading.cancel();
			if(ret.code == 0){
				var msg = '<div class="d_d_gx lh25 mt25 mb30 f14 c_777">';
				msg += '<img class="img" src="http://res.ckimg.com/sites/www/v2/images/public/ico_ok_25x25.png">';
				msg += '<p>已加入购物车！</p>';
				msg += '<p class="f12"><a href="/?mod=cart&act=show" target="_blank">查看我的购物车>></a></p>';
				msg += '</div>';
				msg += '<p class="tc">';
				msg += '<a href="javascript:;" id="try_success_confirm" class="c_btn37a"><span>确 定</span></a>';
				msg += '</p>';
				var ajaxBox = $.ckBoxy({
					content: msg,
					title : "提示",
					width : 338,
					height : 236,
					callback : function(){
						$(".close").click(function(){
							ajaxBox.cancel();
						});
						$("#try_success_confirm").live('click', function(){
							ajaxBox.cancel();
						});
					}
				});
				KK.updateCartCount();
			} else {
				$.ckAlert({message:ret.data});
			}
		}
	});
}

var course_package_hanlder = function(data) {
	//套餐菜单
	var html = '<div class="details-packages"><div class="m-nav cf"><div class="fl package-tab"><ul style="width: 2000px;">';
	for (var i=0; i<data.length; i++) {
		html += [
		    (i==0)
		    ?
	        '<li><a class="link curr" href="javascript:;" pack="'+data[i].PackID+'">课程套餐'+parseInt(i+1)+'</a></li>'
	        :
	        '<li><a class="link" href="javascript:;" pack="'+data[i].PackID+'">课程套餐'+parseInt(i+1)+'</a></li>'
		].join('');
	}
	html += '</ul></div>';
    if(data.length > 7){
        html += '<div class="fr"><span class="fl num"><em class="cor">1</em>/2</span><a href="javascript:;" class="fl prev disabled"  id="coursepackagebefore"> < </a><a href="javascript:;" class="fl next" id="coursepackagenext"> > </a></div>';
    }
    html += '</div>';
	//套餐详情
	for (var i=0; i<data.length; i++) {
		html += i == 0 ? '<div class="detailspackages-list" packid="'+data[i].PackID+'">' : '<div class="detailspackages-list" packid="'+data[i].PackID+'" style="display:none;">';
		
		
		html += '<div class="fl details-packages-list"><ul class="packages-list1" id="package_'+data[i].PackID+'">';
		var pack_count = parseInt(data[i].Courses.length)-1;
		if (pack_count <= 0) {
			return;
		}
		for (var j=0; j<=pack_count; j++) {
			html += '<li><span class="fl ico-plus"></span><div class="item-panel"><div class="item-pic">';
			html += '<a href="'+data[i].Courses[j].CourseURL+'" target="_blank"><img src="'+data[i].Courses[j].PhotoURL+'" width="208" height="156"/></a>';
			if (data[i].Courses[j].Type == 1) {
				html += '<i class="ico-item ico-item-yj">优+</i>';
			} else if (data[i].Courses[j].Type == 2){
				html += ' <i class="ico-item ico-item-dj">独家</i>';
			}
			if (data[i].Courses[j].TrialClass == 1) {
				html += '<i title="试听" class="ico-item ico-item-st">试听</i>';
			} 
			html += [
		        '</div><div class="item-title"><a href="'+data[i].Courses[j].CourseURL+'" target="_blank">'+data[i].Courses[j].CourseName+'</a></div>',
		        '<div class="item-addition"><div class="price">',
		    ].join('');
			if(data[i].Courses[j].Cost > 0){
				html += '<span class="hot-price"><em>￥</em>' + data[i].Courses[j].Cost + '</span>';
			} else {
				html += '<span class="ico-xm">限免</span>';
			}
			html += '</div><div class="number">' + data[i].Courses[j].ClassHour + '课时</div></div></div>';
			html += '</li>';
		}
		html += '</ul></div>';
		html += '<div class="fr details-packages-price">';
		html += [
            '<i class="fl ico-equal"></i><ul>',
            '<li class="c-orange">套餐价: <em class="fb">￥'+data[i].PackCost+'</em></li>',
            '<li><span class="province">省: ￥'+data[i].Preferential+'</span></li>',
            '<li class="total">原总价：<del class="del">'+data[i].Cost+'</del></li>',
            '<li><a href="javascript:;" class="ck-btn ck-btn7" onclick="packtoCart('+data[i].PackID+');">购买套餐</a></li>',
            '</div></div>'
		].join('');
	}
	html += '</ul></div></div>';
	return html;
}

$(function(){
	$("#selected_class").val('');
	
	$("#btnList").show();
	var hash = location.hash;
	
	//装载课程简介
	if(hash == '#comment'){
		$("#tab_switch li a").removeClass('curr');
		$('li[tab=comment] a').addClass('curr');
		getBoxContent('comment');
	} else {
		getBoxContent('brief');
	}
	
	//收藏课程
	$("#collect_course").live('click',function(){
		if(KK.checkLogin() === false){
			$.ckLoginBoxy();
			return false;
		}else{
			var loading = null;
			$.ajax({
				url:'/?mod=course&act=show&do=collect&sid='+Course.SID+'&courseid='+Course.CourseID+'&r='+Math.random(),
				type:'get',
				dataType:'json',
				success:function(ret) {
					if (ret.code == 0) {
						var collect_course_num = parseInt($("#collect_course_num").text());
						collect_course_num = collect_course_num + 1;
						$("#collect_course").attr('id', 'uncollect_course').addClass('curr').html('<i class="ico-collect"></i> 已收藏（<span id="collect_course_num">'+collect_course_num+'</span>）');
					} else {
						$.ckAlert({message:ret.data});
					}
				}
			});
			return false;
		}
	});
	
	$("#uncollect_course").live('click',function(){
		if(KK.checkLogin() === false){
			$.ckLoginBoxy();
			return false;
		}else{
			var loading = null;
			$.ajax({
				url:'/?mod=course&act=show&do=uncollect&sid='+Course.SID+'&courseid='+Course.CourseID+'&r='+Math.random(),
				type:'get',
				dataType:'json',
				success:function(ret) {
					if (ret.code == 0) {
						var collect_course_num = parseInt($("#collect_course_num").text());
						if(collect_course_num > 0){
							collect_course_num = collect_course_num - 1;
						}
						$("#uncollect_course").attr('id', 'collect_course').removeClass('curr').html('<i class="ico-collect"></i> 收藏（<span id="collect_course_num">'+collect_course_num+'</span>）');
					} else {
						$.ckAlert({message:ret.data});
					}
				}
			});
			return false;
		}
	});
	
	//收藏学校
	$("#collect_school").live('click',function(){
		if(KK.checkLogin() === false){
			$.ckLoginBoxy();
			return false;
		}else{
			$.ajax({
				url:'/?mod=school&act=edit&do=collect&sid='+Course.SID+'&r='+Math.random(),
				type:'get',
				dataType:'json',
				success:function(ret) {
					if (ret.code == 0) {
						var collect_school_num = parseInt($("#collect_school_num").text());
						collect_school_num = collect_school_num + 1;
						$("#collect_school_num").text(collect_school_num);
						$("#collect_school").attr('id', 'uncollect_school').text('已收藏');
					} else {
						$.ckAlert({message:ret.data});
					}
				}
			});
			return false;
		}
	});
	
	//取消收藏学校
	$("#uncollect_school").live('click',function(){
		if(KK.checkLogin() === false){
			$.ckLoginBoxy();
			return false;
		}else{
			$.ajax({
				url:'/?mod=school&act=edit&do=unCollect&sid='+Course.SID+'&r='+Math.random(),
				type:'get',
				dataType:'json',
				success:function(ret) {
					if (ret.code == 0) {
						var collect_school_num = parseInt($("#collect_school_num").text());
						if(collect_school_num > 0){
							collect_school_num = collect_school_num - 1;
						}
						$("#collect_school_num").text(collect_school_num);
						$("#uncollect_school").attr('id', 'collect_school').text('收藏学校');
					} else {
						$.ckAlert({message:ret.data});
					}
				}
			});
			return false;
		}
	});
	
	if (hash == '#cart') {
		addtoCart();
	}
	
	if (hash == '#buy') {
		var buy_type = $("#buy_course_type").text();
		
		if(KK.checkLogin() === false){
			/*
			 * 单课购买不做购买下一步跳转
			 */
			if (buy_type == 2) {
				$.ckLoginBoxy();
			} else {
				var url = 'http://www.chuanke.com/'+Course.SID+'-'+Course.CourseID+'.html#buy';
				url = KK.base64_encode(url);
				url = url.replace(/\//, '_');
				location.href = "http://passport.chuanke.com/login/index/ret/"+url;
			}
			return false;
		}else{
			if (Course.Cost == 0) {
				//如果是免费课程，则调用免费购买
				$.ajax({
					url:'/?mod=order&act=create&do=freebuy&sid='+Course.SID+'&courseid='+Course.CourseID+'&r='+Math.random(),
					type:'get',
					dataType:'json',
					success:function(ret) {
						if (ret.code == 0) {
							$.get('/?mod=index&act=index&do=redirect&type=freebuy&returl='+encodeURIComponent('/?mod=student&act=study&courseid='+Course.CourseID)+'&rand='+Math.random(), function(rethtml){
								var Box = $.ckRedirectBoxy({
									content : rethtml,
									width : 421,
									height : 97
								});
							});
						} else {
							$.ckAlert({message:ret.data});
						}
					}
				});
				return false;
			} else {
				//判断单课购买				
				if (buy_type == 2) {
					var cids = $("#selected_class").val();
					if (!cids) {
						$(".extra_gmlx_txt").show();
						return false;
					}
				} else {
					cids = 0;
				}
				
				$.ajax({
					url:'/?mod=order&act=show&do=checkCourseCost&sid='+Course.SID+'&courseid='+Course.CourseID+'&cids='+cids+'&rand='+Math.random(),
					type:'get',
					async:false,
					dataType:'json',
					success:function(ret){
						if (ret.code == '1') {
							//整课免费购买
							$.ajax({
								url:'/?mod=order&act=create&do=freebuy&sid='+Course.SID+'&courseid='+Course.CourseID+'&r='+Math.random(),
								type:'get',
								async:false,
								dataType:'json',
								success:function(rs) {
									if (rs.code == 0) {
										$.get('/?mod=index&act=index&do=redirect&type=freebuy&returl='+encodeURIComponent('/?mod=student&act=study&courseid='+Course.CourseID)+'&rand='+Math.random(), function(rethtml){
											var Box = $.ckRedirectBoxy({
												content : rethtml,
												width : 421,
												height : 97
											});
										});
									} else {
										$.ckAlert({message:rs.data});
									}
									return false;
								}
							});
						} else if (ret.code == '2') {
							//单课免费购买
							$.ajax({
								url:'/?mod=order&act=create&do=freebuy&sid='+Course.SID+'&courseid='+Course.CourseID+'&cids='+cids+'&r='+Math.random(),
								type:'get',
								async:false,
								dataType:'json',
								success:function(rs) {
									if (rs.code == 0) {
										$.get('/?mod=index&act=index&do=redirect&type=freebuy&returl='+encodeURIComponent('/?mod=student&act=study&courseid='+Course.CourseID)+'&rand='+Math.random(), function(rethtml){
											var Box = $.ckRedirectBoxy({
												content : rethtml,
												width : 421,
												height : 97
											});
										});
									} else {
										$.ckAlert({message:rs.data});
									}
									return false;
								}
							});
						} else if (ret.code == '0') {
							//付费购买
							$.ajax({
								url:'/?mod=cart&act=operate&do=add&sid='+Course.SID+'&courseid='+Course.CourseID+'&cids='+cids+'&token='+ptoken+'&r='+Math.random(),
								type:'get',
								dataType:'json',
								beforeSend:function(){
									loading = $.ckTipsBoxy({type:"loading", mask:true, message:"提交数据中..."});
								},
								success:function(ret) {
									loading.cancel();
									window.location.href = "/?mod=cart&act=show";
								}
							});
						}
					}
				});
			}
			
			return false;
		}
	}
	
	//立刻购买
	$("a.buyBtn").click(function(){
		cTime = 3;
		if(RetURL == 0){
			var buy_type = $("#buy_course_type").text();
			
			if(KK.checkLogin() === false){
				/*
				 * 单课购买不做购买下一步跳转
				 */
				if (buy_type == 2) {
					$.ckLoginBoxy();
				} else {
					var url = 'http://www.chuanke.com/'+Course.SID+'-'+Course.CourseID+'.html#buy';
					url = KK.base64_encode(url);
					url = url.replace(/\//, '_');
					location.href = "http://passport.chuanke.com/login/index/ret/"+url;
				}
				return false;
			}else{
				if (Course.Cost == 0) {
					//如果是免费课程，则调用免费购买
					$.ajax({
						url:'/?mod=order&act=create&do=freebuy&sid='+Course.SID+'&courseid='+Course.CourseID+'&r='+Math.random(),
						type:'get',
						dataType:'json',
						success:function(ret) {
							if (ret.code == 0) {
								$.get('/?mod=index&act=index&do=redirect&type=freebuy&returl='+encodeURIComponent('/?mod=student&act=study&courseid='+Course.CourseID)+'&rand='+Math.random(), function(rethtml){
									var Box = $.ckRedirectBoxy({
										content : rethtml,
										width : 421,
										height : 97
									});
								});
							} else if (ret.code == '3') {
								setInterval("timerRedirect();", 1000);
								$.ckAlert({message:ret.data, width:500, height:200});
							} else {
								$.ckAlert({message:ret.data});
							}
						}
					});
					return false;
				} else {
					//判断单课购买				
					if (buy_type == 2) {
						var cids = $("#selected_class").val();
						if (!cids) {
							$(".extra_gmlx_txt").show();
							return false;
						}
					} else {
						cids = 0;
					}
					
					$.ajax({
						url:'/?mod=order&act=show&do=checkCourseCost&sid='+Course.SID+'&courseid='+Course.CourseID+'&cids='+cids+'&rand='+Math.random(),
						type:'get',
						async:false,
						dataType:'json',
						success:function(ret){
							if (ret.code == '1') {
								//整课免费购买
								$.ajax({
									url:'/?mod=order&act=create&do=freebuy&sid='+Course.SID+'&courseid='+Course.CourseID+'&r='+Math.random(),
									type:'get',
									async:false,
									dataType:'json',
									success:function(rs) {
										if (rs.code == 0) {
											$.get('/?mod=index&act=index&do=redirect&type=freebuy&returl='+encodeURIComponent('/?mod=student&act=study&courseid='+Course.CourseID)+'&rand='+Math.random(), function(rethtml){
												var Box = $.ckRedirectBoxy({
													content : rethtml,
													width : 421,
													height : 97
												});
											});
										} else {
											$.ckAlert({message:rs.data});
										}
										return false;
									}
								});
							} else if (ret.code == '2') {
								//单课免费购买
								$.ajax({
									url:'/?mod=order&act=create&do=freebuy&sid='+Course.SID+'&courseid='+Course.CourseID+'&cids='+cids+'&r='+Math.random(),
									type:'get',
									async:false,
									dataType:'json',
									success:function(rs) {
										if (rs.code == 0) {
											$.get('/?mod=index&act=index&do=redirect&type=freebuy&returl='+encodeURIComponent('/?mod=student&act=study&courseid='+Course.CourseID)+'&rand='+Math.random(), function(rethtml){
												var Box = $.ckRedirectBoxy({
													content : rethtml,
													width : 421,
													height : 97
												});
											});
										} else if (rs.code == 3) {
											setInterval("timerRedirect();", 1000);
											$.ckAlert({message:rs.data, width:500, height:200});
										} else {
											$.ckAlert({message:rs.data});
										}
										return false;
									}
								});
							} else if (ret.code == '3') {
								setInterval("timerRedirect();", 1000);
								$.ckAlert({message:ret.data, width:500, height:200});
							} else if (ret.code == '4') {
								window.location.href = ret.data;
							} else if (ret.code == '0') {
								//付费购买
								$.ajax({
									url:'/?mod=cart&act=operate&do=add&sid='+Course.SID+'&courseid='+Course.CourseID+'&cids='+cids+'&token='+ptoken+'&r='+Math.random(),
									type:'get',
									dataType:'json',
									beforeSend:function(){
										loading = $.ckTipsBoxy({type:"loading", mask:true, message:"提交数据中..."});
									},
									success:function(ret) {
										loading.cancel();
										window.location.href = "/?mod=cart&act=show";
									}
								});
							}
						}
					});
				}
				
				return false;
			}
		} else {
			window.location.href = RetURL;
		}
	});
	
	//报名试听
	$(".a_lkst").click(function(){
		if(KK.checkLogin() === false){
			$.ckLoginBoxy();
			return false;
		}else{
			$.ajax({
				url:'/?mod=order&act=create&do=trial&sid='+Course.SID+'&courseid='+Course.CourseID+'&r='+Math.random(),
				type:'get',
				dataType:'json',
				success:function(ret) {
					if (ret.code == 0) {
						window.location.href = ret.data;
					} else {
						$.ckAlert({message:ret.data});
					}
				}
			});
			return false;
		}
	});
	
	//加入购物车
	$("#addToCart").click(function(){
		addtoCart();
	});
	
	//单课购买
	$(".gmlx_zk").click(function(){
		$(".gmlx_bf").removeClass('cur');
		$(this).addClass('cur');
		$(".gmlx_bf_tips").hide();
		$(".extra_gmlx_txt").hide();
		$("#buy_course_type").text('1');
	});
	
	$(".gmlx_bf").click(function(){
		$(".gmlx_zk").removeClass('cur');
		$(this).addClass('cur');
		$(".gmlx_bf_tips").show();
		$(".extra_gmlx_txt").show();
		$("#buy_course_type").text('2');
		$("#select_class").trigger('click');
	});
	
	$("#select_class").click(function(){
		var Box = $.ckAjaxBoxy({
			url : '/?mod=course&act=show&do=content&sid='+Course.SID+'&courseid='+Course.CourseID+'&rand='+Math.random(),
			title : '请选择你要购买的章节<span class="c_333">（<em class="c_f60">'+Course.ClassCost/100+'</em>元/节）</span>',
			width : 712,
			height : 536,
			callback:function(){
				$("#fe_dialogBox").find("a.cancel").unbind().bind('click', function(){
					Box.cancel();
				});
			}
		});
		return false;
	});
	
	//机构同类课程和热门课程异步触发
/*	$.ajax({
		url:"/?mod=course&act=show&do=SimilarHot&sid="+Course.SID+"&courseid="+Course.CourseID+"&r="+Math.random(),
		type:"get",
		beforeSend:function(){
			$("#similar_hot").html('<div class="tc pt30"><img border="0" src="http://res.ckimg.com/sites/www/v2/images/public/loading.gif" /></div>');
		},
		success:function(data) {
			$("#similar_hot").html(data);
		}
	});*/
	var offset = $("#tabs").offset();

	/**
	 * 强制静态页面标签按钮切换。此方法无意义。实际调用的为下面被注释的ajax
	 */
	var initFunction = function () {
		$('ul.packages-list1').each(function () {
			$(this).width($(this).children().length * 223);
		});
		var tabsheight = parseInt(offset.top) + parseInt($('div.details-packages').height());
		$(window).scroll(function(){
			var scrollTop = $(this).scrollTop();
			if((scrollTop >= tabsheight)){
				$("#tabs").addClass('fixed');
			}else{
				$("#tabs").removeClass('fixed');
			}
		});
		//标签切换
		$("#tab_switch li[float!=float]").click(function(){
			if ($(this).hasClass('szbq')) {
				return true;
			}
			//根据tab获取不同的数据，并替换内容。此方式可根据需要变动
			var tab = $(this).attr('tab');
			console.log(tab);

			$("#tab_switch li a").removeClass('curr');
			$(this).children('a').addClass('curr');
			if (tab == 'comment' && Course.CommentVote == 1) {
				/**
				 * 跳转至投票页面
				 */
				getCommentVote();
			} else {
				/**
				 * 跳转至课程详情页面
				 */
				getBoxContent(tab);
			}

			return false;
		});
		//学生模块“更多”操作
		$("#comment_tab_switch").click(function(){
			$("#tab_switch li a").removeClass('curr');
			$("#tab_switch li[id='comment'] a").addClass('curr');
			if (Course.CommentVote == 1) {
				getCommentVote();
			} else {
				getBoxContent('comment');
			}
			return false;
		});
	}
	initFunction()
	//课程套餐异步触发
    /*$.ajax({
        url:'/?mod=course&act=package&sid='+Course.SID+'&courseid='+Course.CourseID+'&r='+Math.random(),
        type:'get',
        dataType:'json',
        success:function(ret) {
            if (ret.code == 0) {
            	var _html = course_package_hanlder(ret.data);
                $('#coursepackage').html(_html);
                $('ul.packages-list1').each(function () {
                	$(this).width($(this).children().length * 223);
                });
                var tabsheight = parseInt(offset.top) + parseInt($('div.details-packages').height());
                $(window).scroll(function(){
            		var scrollTop = $(this).scrollTop();
            		if((scrollTop >= tabsheight)){
            			$("#tabs").addClass('fixed');
            		}else{
            			$("#tabs").removeClass('fixed');
            		}
            	});
                //标签切换
            	$("#tab_switch li[float!=float]").click(function(){
            		if ($(this).hasClass('szbq')) {
            			return true;
            		}
            		
            		var tabsheight = parseInt(offset.top)+parseInt($('div.details-packages').height());
            		var tab = $(this).attr('tab');
            		$("#tab_switch li a").removeClass('curr');
            		$(this).children('a').addClass('curr');
            		if($(window).scrollTop() > tabsheight){
            			$(window).scrollTop(tabsheight);
            		}
            		if (tab == 'comment' && Course.CommentVote == 1) {
            			getCommentVote();
            		} else {
            			getBoxContent(tab);
            		}
            		
            		return false;
            	});
            	//学生模块“更多”操作
            	$("#comment_tab_switch").click(function(){
            		$("#tab_switch li a").removeClass('curr');
            		$("#tab_switch li[id='comment'] a").addClass('curr');
            		var tabsheight = parseInt(offset.top)+parseInt($('div.details-packages').height());
            		$(window).scrollTop(tabsheight);
            		if (Course.CommentVote == 1) {
            			getCommentVote();
            		} else {
            			getBoxContent('comment');
            		}
            		return false;
            	});
            } else {
            	var tabsheight = parseInt(offset.top);
                $(window).scroll(function(){
            		var scrollTop = $(this).scrollTop();
            		if((scrollTop >= tabsheight)){
            			$("#tabs").addClass('fixed');
            		}else{
            			$("#tabs").removeClass('fixed');
            		}
            	});
                //标签切换
            	$("#tab_switch li[float!=float]").click(function(){
            		if ($(this).hasClass('szbq')) {
            			return true;
            		}
            		
            		var tabsheight = parseInt(offset.top)-5 ;
            		var tab = $(this).attr('tab');
            		$("#tab_switch li a").removeClass('curr');
            		$(this).children('a').addClass('curr');
            		if($(window).scrollTop() > tabsheight){
            			$(window).scrollTop(tabsheight);
            		}
            		if (tab == 'comment' && Course.CommentVote == 1) {
            			getCommentVote();
            		} else {
            			getBoxContent(tab);
            		}
            		
            		return false;
            	});
            	//学生模块“更多”操作
            	$("#comment_tab_switch").click(function(){
            		$("#tab_switch li a").removeClass('curr');
            		$("#tab_switch li[id='comment'] a").addClass('curr');
            		var tabsheight = parseInt(offset.top)-5;
            		$(window).scrollTop(tabsheight);
            		if (Course.CommentVote == 1) {
            			getCommentVote();
            		} else {
            			getBoxContent('comment');
            		}
            		return false;
            	});
            }
        }
    });*/
    
    //切换课程套餐菜单
    $("#coursepackage .details-packages .m-nav li a").live("click", function() {
    	$('.m-nav li a').removeClass('curr');
    	$(this).addClass('curr');
    	var pack_id = $(this).attr('pack');
    	$(".detailspackages-list").each(function(){
    		if($(this).attr('packid') == pack_id) {
    			$(this).show();
    		} else {
    			$(this).hide();
    		}
    	});
    });
    $("#coursepackagenext").live("click", function() {
        $('.m-nav li a').removeClass('curr');
        $("#coursepackage .details-packages .m-nav li:lt(7)").hide();
        $("#coursepackage .details-packages .m-nav li:gt(6)").show();
        $('.m-nav li a:eq(7)').addClass('curr');
        $(this).addClass('disabled');
        $("#coursepackagebefore").removeClass('disabled');
        $(".detailspackages-list").hide();
        $(".detailspackages-list:eq(7)").show();
    });

    $("#coursepackagebefore").live("click", function() {
        $('.m-nav li a').removeClass('curr');
        $("#coursepackage .details-packages .m-nav li:lt(7)").show();
        $("#coursepackage .details-packages .m-nav li:gt(6)").hide();
        $('.m-nav li a:eq(0)').addClass('curr');
        $(this).addClass('disabled');
        $("#coursepackagenext").removeClass('disabled');
        $(".detailspackages-list").hide();
        $(".detailspackages-list:eq(0)").show();
    });


/*   if(Course.Cost > 0){
	 //课程适用优惠券异步加载
		$.ajax({
			url:"/?mod=course&act=coupon&do=show&op=couponlist&sid="+Course.SID+"&courseid="+Course.CourseID+"&r="+Math.random(),
			type:"get",
			success:function(data) {
				$("#coupon_list").html(data);
			}
		});
   }*/
    
});

